package com.coocaa.ops.api.common.validator;

import com.coocaa.ops.api.base.cache.properties.CacheProperties;
import com.coocaa.ops.api.base.model.BaseQueryModel;
import com.coocaa.ops.api.v1.content.model.query.PanelQueryModel;
import com.coocaa.ops.api.v1.policy.model.PolicyModel;

/**
 * @author tangminghong
 * @date 2020-08-05
 */
public class CacheValidator {

    /**
     * 走缓存的情况
     *
     * @param policyCategory
     * @return
     */
    public static boolean useCache(Integer policyCategory) {
        return useCache() && PolicyValidator.isFormalPolicy(policyCategory);
    }

    /**
     * 不走缓存情况
     *
     * @param policyCategory
     * @return
     */
    public static boolean notUseCache(Integer policyCategory) {
        return !useCache() || PolicyValidator.isTestPolicy(policyCategory);
    }

    /**
     * 不走缓存情况
     *
     * @param policy
     * @return
     */
    public static boolean notUseCache(PolicyModel policy) {
        return !useCache() || PolicyValidator.isTestPolicy(policy);
    }

    public static boolean notUseCache(BaseQueryModel query) {
        return  null != query && notUseCache(query.getPolicyCategory());
    }

    /**
     * 是否开启缓存
     *
     * @return
     */
    public static boolean useCache() {
        return CacheProperties.Constants.ENABLE_CACHE;
    }
}
